package org.davidliebman.android.awesomecube;

import javax.microedition.khronos.opengles.GL10;

import android.content.Context;

public class Mirror  {

	public Mesh[][] mSurface = new Mesh[3][3];
	GL10 gl;
	public float mHalf = 1.0f;
	
	public Mirror (Context c) {
		
		for (int x = 0; x < 3; x ++ ) {
			for (int y = 0; y < 3; y ++ ) {
				mSurface[x][y] = new SimpleMirror(c , new Positioning(), (int) ((x-1) * (2 * mHalf)),(int) ((y-1) * (2 * mHalf)), mHalf , 0, 0, TextureLibrary.WHITE);
			}
		}
		
	}
	public int size() {
		return 9;
	}
	
	public Mesh get(int i, int j) {
		return mSurface[i][j];
	}
	
	public void render (GL10 gl, TextureLibrary mLibrary , Positioning mP) {
		
		this.gl = gl;
		for (int x = 0; x < 3; x ++ ) {
			for (int y = 0; y < 3; y ++ ) {
				mSurface[x][y].mLibrary = mLibrary;
				if (mP.rx != 0 || mP.ry != 0) {
					mSurface[x][y].mP2 = mP;
				}
				render(gl, x, y);
			}
		}
	}
	
	public void render(GL10 gl, int i, int j) {
		this.gl = gl;
		SimpleMirror mPad = (SimpleMirror) mSurface[i][j];
		
		gl.glPushMatrix();
		mPad.scaleAndRotateP0(gl);
		mPad.buildMesh(gl);
		
		gl.glPopMatrix();
	}
	
	public void mirrorTiles( OrientationArray mCube) {
		for(int x = 0; x < 3; x ++ ) {
			for (int y = 0; y < 3; y ++ ) {
				mSurface[x][y].mFace3 = mCube.mTile[0][x][2-y];
			}
		}
		
	}
	
	public void setViewingAngle(Positioning mP) {
		for (int x = 0; x < 3; x ++) {
			for (int y = 0; y < 3; y ++) {
				if(mSurface[x][y] != null) 	{
					mSurface[x][y].mP2 = mP;
				}
				
			}
		}
	}
}
